#coding:utf-8
#code by foRK
#QQ:261496481

import sys
import os
import time
import httplib
#from threading import Thread
import time


if len(sys.argv) < 2:
	print 'Version 0.1'
	print '%s [WebSite] [MeunPath]' % sys.argv[0]
	print '%s www.baidu.com list.txt' % sys.argv[0]
	sys.exit(1)

WebSite = sys.argv[1]
MeunPath = sys.argv[2]

def weblist(txt):
	global weblist  #全局定义web目录列表
	weblist = []
	filepath = os.getcwd() + "\\" + txt  #os.getcwd()获取当前目录,实际上就是取得文本的路径
	if not os.path.isfile(filepath):  #判断是否存在文件
		print "file is not found..."
		return 0
	f = open(filepath, "r")  #只读打开
	for line in f.readlines():
		line=line.strip('\n\r')  #去掉\n符号
		if line not in weblist:
			weblist.append(line)  #去重
	f.close()

#weblist = weblist.replace("\n", "")

if __name__ == '__main__':
	weblist(MeunPath)
#	print weblist
	host = WebSite
#	print host
#	print len(weblist)
	I1 = 0  #获取列表第一个元素
	t = time.time()
	while I1 < len(weblist):
		conn = httplib.HTTPConnection(host,80,timeout=10)
		conn.request("GET",weblist[I1])
		response = conn.getresponse()
		result = response.reason  #返回OK或FOUND
		resultNum = response.status #获取返回状态码200,320等等
		if "OK" in result or "Forbidden" in result:
			print "http://"+host+weblist[I1]+"----"+str(resultNum)+":"+result
		I1 = I1 + 1
	print 'used time:%f' % (time.time()-t)
		